package logic

import (
	"context"
	"errors"
	"houseRpc/models"

	"houseRpc/house"
	"houseRpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddLikeLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddLikeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddLikeLogic {
	return &AddLikeLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddLikeLogic) AddLike(in *house.AddLikeRequest) (*house.AddLikeResponse, error) {
	// todo: add your logic here and delete this line

	var err error
	var lk models.Likes

	lk.Userid = in.UserId
	lk.HouseId = in.HouseId

	if err = lk.AddLike(); err != nil {
		logx.Error("房源收藏失败")
		return nil, errors.New("房源收藏失败")
	}
	return &house.AddLikeResponse{
		Userid: in.UserId,
	}, nil
}
